package com.example.mvpdemo.simple1;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.mvpdemo.R;

import androidx.appcompat.app.AppCompatActivity;

public class Simple1Activity extends AppCompatActivity implements WeatherView {
    /**
     * simple1
     *  mvp
     * 发现问题：
     * 当我们的网络请求还在进行时，这个时候我们退出了activity，然后ui层引用还存在，还会回调，其实没有必要了。
     * 当前代码存在隐患
     * 解决方案：
     * 需要进行绑定和解绑 ——>
     * simple2中进行改进
     * @param view
     */

    private TextView mWeatherContent;
    private EditText mCitynameEdit;
    private String cityname = "北京";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple1);

        mWeatherContent = findViewById(R.id.weather_content_tv);
        mCitynameEdit = findViewById(R.id.cityname_edit);
        mCitynameEdit.setText(cityname);

    }


    public void getWeatherData(View view) {

        cityname = mCitynameEdit.getText().toString().trim();
        WeatherPresenter weatherPresenter = new WeatherPresenter(this);
        weatherPresenter.weeather(cityname);

    }

    @Override
    public void onWeatherGetSuccess(String result) {
        mWeatherContent.setText("查询结果：\n" + result);
    }

    @Override
    public void onWeatherGetFail(String result) {
        mWeatherContent.setText("查询结果：\n" + result);
    }

}